#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/14
# Title:
# Tip:
from app.model import Sensor

# 添加传感器
# 格式:
# {
# "sensor_no":"",
# "sensor_name":"",
# "job_time":1
# }
def addSensor(data={}):
    job_name = "job_"+data['sensor_no']
    insert_data = data
    Sensor.insert(insert_data).execute()
    pass

# 修改上下限值
def updateLimit(id=None, minLimit=None, maxLimit=None):
    return Sensor.update(Sensor.max_limit==maxLimit and Sensor.min_limit==minLimit).where(Sensor.id==id).execute()

# 获取所有的传感器
# type:0 所有传感器 | 1 所有可用传感器 | 2 所有不可用传感器
def getAllSensorList(type=0):
    res = None
    if type == 0:
        res = Sensor.select().execute()
    elif type ==1:
        res = Sensor.select().where(Sensor.is_used==True).execute()
    elif type ==2:
        res = Sensor.select().where(Sensor.is_used==False).execute()
    return res

# 修改传感器的当前状态
def updateStatus(sensor_no=None,isUse=True):
    return Sensor.update(Sensor.is_used==isUse).where(
        Sensor.sensor_no == sensor_no).execute()

# 设置传感器类别和单位
def setTypeAndUnitForSensor(sensorNo=None, type='', unit='' ):
    return Sensor.update(Sensor.is_used == isUse).where(
        Sensor.type==type and Sensor.unit==unit).execute()
    pass




#








if __name__ == '__main__':
    pass